import Router from '@koa/router';
import { validateDto } from '../../../middleware/validation';
import { AuthMiddleware } from '../../../middleware/authMiddleware';
import { PermissionController } from '../../../controllers/system/permissionController';
import { CreatePermissionDto, UpdatePermissionDto } from '../../../dtos/system/PermissionDto';

const router = new Router();

const permissionController = new PermissionController();
const authMiddleware = new AuthMiddleware();

// 获取所有角色（需要认证）
router.get('/', authMiddleware.authenticate, permissionController.getPermissions);

// 根据ID获取角色（需要认证）
router.get('/:id', authMiddleware.authenticate, permissionController.getPermissionById);

// 创建角色（需要认证，仅管理员）
router.post('/', authMiddleware.authenticate, authMiddleware.requireRole('admin'), validateDto(CreatePermissionDto), permissionController.createPermission);

// 更新角色（需要认证，仅管理员）
router.put('/:id', authMiddleware.authenticate, validateDto(UpdatePermissionDto, { skipMissingProperties: true }), permissionController.updatePermission);

// 删除角色（需要认证，仅管理员）
router.delete('/:id', authMiddleware.authenticate, authMiddleware.requireRole('admin'), permissionController.deletePermission);

export default router;